package org.redis.cluster.command.info;

import java.util.LinkedHashMap;
import java.util.Map;

import org.redis.cluster.statistics.CommandInvokeStatistics;
import org.redis.cluster.statistics.ConnectionStatistics;
import org.redis.cluster.statistics.KeySpaceStatistics;
import org.redis.cluster.support.ConnectionController;

public class StatsInfoFieldProvider implements InfoFieldProvider {
	
	private final static String GROUP="stats";

	@Override
	public String getGroup() {
		return GROUP;
	}

	@Override
	public Map<String, Object> getFields() {
		Map<String,Object> fields=new LinkedHashMap<String,Object>();
		fields.put("total_connections_received", getTotalConnectionsReceived());
		fields.put("total_commands_processed", getTotalCommandsProcessed());
		fields.put("instantaneous_ops_per_sec", getInstantaneousOpsPerSec());
		fields.put("rejected_connections", getRejectedConnections());
		fields.put("keyspace_hits", getKeyspaceHits());
		fields.put("keyspace_misses", getKeyspaceMisses());
		return fields;
	}
	
	protected int getTotalConnectionsReceived() {
		return ConnectionStatistics.getConnectCount();
	}
	
	protected int getTotalCommandsProcessed() {
		return CommandInvokeStatistics.getInvokeCount();
	}
	
	protected int getInstantaneousOpsPerSec() {
		return CommandInvokeStatistics.getOpsCount();
	}
	
	protected int getRejectedConnections() {
		return ConnectionController.getRefusedConnectionCount();
	}
	
	protected int getKeyspaceHits() {
		return KeySpaceStatistics.getHitCount();
	}
	
	protected int getKeyspaceMisses() {
		return KeySpaceStatistics.getMissCount();
	}

}